package com.getjsp.adapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.getjsp.bean.Domain;
import com.getjsp.fragment.LikeFragment;

import com.getjsp.ui.R;

import android.annotation.SuppressLint;

import android.content.Context;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;

import android.widget.ImageView;

import android.widget.TextView;

public class DomainListAdapter extends BaseAdapter {
	private Context context;
	private List<Domain> domain_list;
	private LikeFragment likeFragment;
	@SuppressLint("UseSparseArrays")
	private Map<Integer, View> newsItemViews = new HashMap<Integer, View>();

	public DomainListAdapter() {
		super();
	}

	@SuppressLint("UseSparseArrays")
	public DomainListAdapter(Context context, List<Domain> domain_list, LikeFragment likeFragment) {
		super();
		this.context = context;
		this.domain_list = domain_list;
		this.likeFragment = likeFragment;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return domain_list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return domain_list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = newsItemViews.get(position);
		if (view == null) {
			view = LayoutInflater.from(context).inflate(R.layout.like_item,
					null);
			Domain domain = (Domain) getItem(position);
			TextView tv_like_domain = (TextView) view.findViewById(R.id.tv_like_domain);
			tv_like_domain.setText(domain.getUrl());
			ImageView iv_deltet = (ImageView) view.findViewById(R.id.iv_delete);
			ItemListener itemListener = new ItemListener(position);
			iv_deltet.setOnClickListener(itemListener);
		}
		return view;
	}
	 class ItemListener implements OnClickListener {
		 private int m_position;
		 
		public ItemListener(int pos) {
			super();
			this.m_position = pos;
		}

		@Override
		public void onClick(View v) {
			Log.v("MyListView-click", "line:" + m_position + ":"+ v.getTag());  
			
			likeFragment.delete_Date(m_position);
			
			
			
		}
		 
	 }





}
